package {
	import com.greensock.TweenMax;
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	
	import org.osflash.signals.Signal;
	
	public class InstructionCircle extends Circle {
		
		public var click:Signal;
		
		public function InstructionCircle(view:MovieClip) {
			super(view);
			view.visible = false;
			view.alpha = 0;
			view.scaleX = view.scaleY = .7;
			click = new Signal();
			view.mouseChildren = true;
			createButton(view.start, "Start");
			view.addEventListener(MouseEvent.MOUSE_DOWN, onClick);
		}
		
		private function onClick(e:MouseEvent):void {
			click.dispatch();
		}
		
		public function show():void {
			_view.visible = true;
			TweenMax.to(_view, .3, {alpha:1, scaleX:1, scaleY:1 });
		}
		
		public function hide():void {
			TweenMax.to(_view, .3, {alpha:0, scaleX:.7, scaleY:.7, onComplete:function():void {
				_view.visible = false;
			} });
		}
		
		protected override function onRollOver(e:MouseEvent):void {
			TweenMax.to(_view.copy, .4 , {glowFilter:{color:0xFFFFFF, alpha:1, blurX:80, blurY:80, quality:3}});
		}
		
		protected override function onRollOut(e:MouseEvent):void {
			TweenMax.to(_view.copy, .4 , {glowFilter:{color:0xFFFFFF, alpha:0, blurX:10, blurY:10}});
		}
		
		private function createButton(m:MovieClip, label:String):MovieClip {
			m.addEventListener(MouseEvent.ROLL_OVER, onMenuButton);
			m.addEventListener(MouseEvent.ROLL_OUT, onMenuButton);
			m.buttonMode = true;
			m.mouseChildren = false;
			m.txt.autoSize = "center";
			m.txt.text = label;
			return m;
		}
		
		private function onMenuButton(e:MouseEvent):void {
			switch(e.type) {
				case MouseEvent.ROLL_OVER :
					TweenMax.to(e.currentTarget, .2, {tint:0xFFFFFF, scaleX:1.1, scaleY:1.1});
					break;
				
				case MouseEvent.ROLL_OUT :
					TweenMax.to(e.currentTarget, .2, {tint:0x000000, scaleX:1, scaleY:1});
					break;
			}
		}
	}
}